#pragma once

#include <ros/ros.h>
#include <tf/tf.h>
#include "task/task_custom_class.h"
#include "task/commnunication/localhost.h"
#include "common_lib/log.h"
#include "common_lib/common.h"
#include "task/command_process.h"
#include "map_operation_msgs/GetPathInfo.h"
#include "map_operation_msgs/GetPointInfo.h"

namespace task
{
    class CommandProcess;
    class TaskProcess
    {
    public:
        TaskProcess(ros::NodeHandle &nh, ros::NodeHandle &private_nh);
        ~TaskProcess();
        void Start();

    private:
        ros::NodeHandle nh_;
        ros::NodeHandle private_nh_;

        std::string map_file_;
        std::string vehicle_param_file_;
        std::string file_path_;
        std::string communication_type_;
        std::shared_ptr<task::CommandProcess> ptr_cmd_process_;
        task::sAMRState amr_state_;
        task::sTaskReceive task_receive_;

        ros::Subscriber sub_control_;
        ros::Subscriber sub_control_state_;
        ros::Subscriber sub_actuator_;

        ros::Publisher pub_task_;

        ros::ServiceClient srv_client_path_info_;
        ros::ServiceClient srv_client_point_info_;

        int local_host_task_cnt_ = 0;
        int local_host_task_times_ = 0;

        void Init();
        void LocalHostProcess();
        void TaskInteract();

        void ControlCallback(const control_msgs::control_msgConstPtr &msg);
        void ControlStateCallback(const control_msgs::control_state_msgConstPtr &msg);
        void ActuatorCallback(const actuator_msgs::actuator_msgConstPtr &msg);

        void StructMsgToRosMsg(task_msgs::task_msg &msg_ros, task::sTaskMsg &msg_struct);
    public:
        bool GetPathInofSrv(map_operation_msgs::GetPathInfoRequest &req, map_operation_msgs::GetPathInfoResponse &resp);
        bool GetPathInofSrv(map_operation_msgs::GetPathInfo &srv);
        bool GetPointInfoSrv(map_operation_msgs::GetPointInfoRequest &req, map_operation_msgs::GetPointInfoResponse &resp);
        bool GetPointInfoSrv(map_operation_msgs::GetPointInfo &srv);
        bool GetPointInfoSrv(std::string &pointid, sTaskPoint &point);
    };
};